package com.ymatou.iapi.cardservice.parameter;

public enum StatusCodeEnum {
	 /**
     * 0：表示执行成功
     */
    Success(0, "执行成功"),

    /**
     * 1：表示参数异常
     */
    ArgumentException(1, "参数异常"),


    /**
     * 2:完全幂等
     */
    FullIdempotencyException(2, "完全幂等"),

    /**
     * 3：多笔中有一笔幂等
     */
    MultiIdempotencyException(3, "多笔中有一笔幂等"),

    /**
     * 4：幂等异常
     */
    Idempotency(4, "幂等异常"),

    /**
     * 5：表示系统异常
     */
    SystemException(5, "系统异常"),

    /**
     * 6:卡不存在
     */
    CardNotExit(6, "卡不存在"),

    /**
     * 7:卡内可用余额不足
     */
    AvailbeInsufficient(7, "卡内可用余额不足"),


    /**
     * 8:卡不可用
     */
    CardUnAvaible(8, "卡不可用"),

    /**
     * 9:超出面额值
     */
    OvertopDenomination(9,"超出面额值"),

    /**
     * 10:自动开户发生异常
     */
    BandingCardException(10, "绑卡发生异常"),


    /**
     * 11:无效的账户操作动作
     */
    InvalideOperation(11, "无效的账户操作动作"),
    /**
     * 12:退款金额无效
     */
    RefundAmountInvalide(12, "退款金额无效"),

    /**
     * 13:卡已绑定
     */
    CardIsBinding(13, "卡已绑定"),

    /**
     * 14:卡未激活
     */
    CardUnactivated(14, "卡未激活"),

    /**
     * 99:未知的异常
     */
    UnknowException(99, "未知的异常");


    private int code;

    private String message;

    StatusCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }


    /**
     * 通过代码获取枚举项
     *
     * @param code
     * @return
     */
    public static StatusCodeEnum getByCode(int code) {
        for (StatusCodeEnum statusCodeEnum : StatusCodeEnum.values()) {
            if (statusCodeEnum.getCode() == code) {
                return statusCodeEnum;
            }
        }
        return null;
    }

    /**
     * 通过名称获取枚举项
     *
     * @param name 枚举名称
     * @return
     */
    public static StatusCodeEnum getByName(String name) {
        for (StatusCodeEnum statusCodeEnum : StatusCodeEnum.values()) {
            if (statusCodeEnum.name().equalsIgnoreCase(name)) {
                return statusCodeEnum;
            }
        }
        return null;
    }

    /**
     * 通过枚举值或枚举名称获取枚举项
     *
     * @param value 枚举值或枚举名称
     * @return
     */
    public static StatusCodeEnum getValue(String value) {
        if (value == null)
            return null;
        value = value.trim();
        for (StatusCodeEnum statusCodeEnum : StatusCodeEnum.values()) {
            if (statusCodeEnum.name().equalsIgnoreCase(value) || String.valueOf(statusCodeEnum.getCode()).equalsIgnoreCase(value)) {
                return statusCodeEnum;
            }
        }
        return null;
    }
}
